package com.reebake.ideal.message.controller;

import java.util.List;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.reebake.ideal.mybatis.core.PageResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.reebake.ideal.message.entity.MessageHistory;
import com.reebake.ideal.message.service.MessageHistoryService;
import com.reebake.ideal.message.vo.MessageHistoryQueryParamVO;
import com.reebake.ideal.message.vo.MessageHistoryVO;

 /**
 * 消息记录控制层
 */
@Tag(name = "消息记录对象功能接口")
@RestController
@RequestMapping("/message/history")
public class MessageHistoryController {
    @Autowired
    private MessageHistoryService messageHistoryService;
    
    /** 
     * 分页查询
     *
     * @param queryParam 查询参数
     * @return 查询结果
     */
    @Operation(summary = "分页查询")
    @PostMapping("page")
    public PageResult<MessageHistoryVO> page(@RequestBody MessageHistoryQueryParamVO queryParam) {
        LambdaQueryWrapper<MessageHistory> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StrUtil.isNotBlank(queryParam.getMessageTemplateId()), MessageHistory::getMessageTemplateId, queryParam.getMessageTemplateId());
        queryWrapper.like(StrUtil.isNotBlank(queryParam.getReceiverId()), MessageHistory::getReceiverId, queryParam.getReceiverId());
        
        queryParam = messageHistoryService.page(queryParam, queryWrapper);
        
        return queryParam.to(MessageHistoryVO.class);
    }
    
    /** 
     * 保存或更新数据
     *
     * @param messageHistory 实例对象
     */
    @Operation(summary = "保存或更新数据")
    @PostMapping("save")
    public void save(@RequestBody MessageHistoryVO messageHistory) {
        messageHistoryService.saveOrUpdate(BeanUtil.copyProperties(messageHistory, MessageHistory.class));
    }
    
    /** 
     * 通过主键批量删除
     *
     * @param messageHistoryIds 主键
     */
    @Operation(summary = "通过主键批量删除")
    @PostMapping("remove-by-ids")
    public void removeByIds(@RequestBody List<String> messageHistoryIds) {
        messageHistoryService.removeByIds(messageHistoryIds);
    }
}